// 10秒后执行这个闭包
setTimeout(function(){console.log("tell the worker to stop.");stop =true },1000 * 10)


var stop = false

// 循环延时器
// 每2秒工作一次，等待别人通知结束。
function work(){
	if(stop){
		console.log("complete...")
	}else{
		setTimeout(work,2000)
		console.log("work during 2 seconds,")
	}
}

work();